package com.wy.service;

import java.io.Serializable;
import java.util.List;

import org.nutz.dao.Chain;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.springframework.transaction.annotation.Transactional;

import com.wy.dao.AbsDao;
import com.wy.page.AbsPage;
import com.wy.result.Result;

public abstract class AbsService<T> {

	public abstract AbsDao<T> getDao();

	public Dao getBaseDao() {
		return getDao().getDao();
	}

	public Class<T> getClassOfT() {
		return getDao().getClassOfT();
	}

	@Transactional
	public Object save(T model) {
		return getDao().save(model);
	}

	@Transactional
	public Object saveSort(T model) {
		return getDao().saveSort(model);
	}

	@Transactional
	public Object saveSort(T model, String sortColumn) {
		return getDao().saveSort(model, sortColumn);
	}

	@Transactional
	public Object saves(List<T> ts) {
		return getDao().saves(ts);
	}

	@Transactional
	public int delete(Serializable id) {
		return getDao().delete(id);
	}

	@Transactional
	public int deletes(List<? extends Serializable> ids) {
		return getDao().deletes(ids);
	}

	@Transactional
	public Object update(T model) {
		return getDao().update(model);
	}

	@Transactional
	public Object update(Chain chain, Cnd cnd) {
		return getBaseDao().update(getClassOfT(), chain, cnd);
	}

	@Transactional
	public <K> Object update(Class<K> clazz, Chain chain, Cnd cnd) {
		return getBaseDao().update(clazz, chain, cnd);
	}

	public boolean hasValue(String column, Object value) {
		return getDao().hasValue(column, value);
	}

	public boolean hasValue(Class<?> clazz, String column, Object value) {
		return getDao().hasValue(clazz, column, value);
	}

	public boolean hasValue(String table, String column, Object value) {
		return getDao().hasValue(table, column, value);
	}

	public Object getById(Serializable id) {
		return getDao().getById(id);
	}

	protected T fetch(Serializable id) {
		return getDao().getById(id);
	}

	protected T fetch(Cnd cnd) {
		return getBaseDao().fetch(getClassOfT(), cnd);
	}

	protected <K> K fetch(Class<K> clazz, Serializable id) {
		return getDao().getById(id, clazz);
	}

	protected <K> K fetch(Class<K> clazz, Cnd cnd) {
		return getBaseDao().fetch(clazz, cnd);
	}

	protected long[] getOrgChild(int groupId) {
		return getDao().getOrgChild(groupId);
	}

	protected List<T> getEntitys(T t) {
		return getDao().getEntitys(t);
	}

	public Result getEntitys(Integer pageIndex, Integer pageSize) {
		return getDao().getEntitys(pageIndex, pageSize);
	}

	public Result getEntitysByCnd(T page) {
		return getDao().getEntitysByCnd(page);
	}

	public Result getList(AbsPage page) {
		return getDao().getList(page);
	}
}